﻿// 事件触发监听      
// 功能： 实现对于任何对象的监听处理。

using System;
using UnityEngine;
using UnityEngine.EventSystems;

namespace MotionFramework.UIKit
{
    public class EventTriggerListener : EventTrigger 
    {
        public Action onClick;
        public Action onDown;
        public Action onEnter;
        public Action onExit;
        public Action onUp;
        public Action onSelect;
        public Action onUpdateSelect;

        /// <summary>
        /// 得到“监听器”组件
        /// </summary>
        public static void Get(GameObject gameObject, out EventTriggerListener component)
        {
            if (!gameObject.TryGetComponent<EventTriggerListener>(out component))
            {
                component = gameObject.AddComponent<EventTriggerListener>();
            }
        }

        public override void OnPointerClick(PointerEventData eventData)
        {
            onClick?.Invoke();
        }

        public override void OnPointerDown(PointerEventData eventData)
        {
            onDown?.Invoke();
        }

        public override void OnPointerEnter(PointerEventData eventData)
        {
            onEnter?.Invoke();
        }

        public override void OnPointerExit(PointerEventData eventData)
        {
            onExit?.Invoke();
        }

        public override void OnPointerUp(PointerEventData eventData)
        {
            onUp?.Invoke();
        }
    
        public override void OnSelect(BaseEventData eventBaseData)
        {
            onSelect?.Invoke();
        }

        public override void OnUpdateSelected(BaseEventData eventBaseData)
        {
            onUpdateSelect?.Invoke();
        }
	
    }//Class_end
}
